package com.sen.demo;

import org.slf4j.MDC;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @className: LogHandler
 * @Auther: jiesen.liu
 * @Date: 2019/7/17 10:45
 * @package: com.sen.demo
 */
public class LogHandler implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException {
        HandlerMethod h = (HandlerMethod) handler;
        String logFileName = h.getBeanType().getSimpleName();
        MDC.put("LOG_WEB", logFileName);
        return true;
    }
}
